package com.ihg.hiex.admin.web.controller.data;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.demo2do.core.entity.page.Page;
import com.demo2do.core.web.interceptor.MenuSetting;
import com.ihg.hiex.admin.service.DataService;
import com.ihg.hiex.entity.data.conference.ConferenceRoom;

/**
 * 会议室管理
 * 
 * @author houtao
 *
 */
@Controller
@RequestMapping("/conferences")
@MenuSetting("menu-settings")
public class ConferenceController {

    @Autowired
    @Qualifier("dataService")
    private DataService<ConferenceRoom> conferenceRoomService;

    /**
     * list all the conference room
     * 
     * @param page
     * @return
     */
    @MenuSetting("submenu-conference-management")
    @RequestMapping(value = "", method = RequestMethod.GET)
    public ModelAndView list(Page page) {

        ModelAndView modelAndView = new ModelAndView("settings/conference/conference-list");
        
        int totals = conferenceRoomService.count(ConferenceRoom.class);
        if (totals > 0) {
            
            List<ConferenceRoom> conferenceRooms = conferenceRoomService.listByPage(ConferenceRoom.class, page.with(totals));
            
            modelAndView.addObject("conferenceRooms", conferenceRooms);
            modelAndView.addObject("page", page);
            
        }
        
        return modelAndView;
        
    }
    
//    /**
//     * prepare to edit zoom
//     * 
//     * @param id
//     * @return
//     */
//    @RequestMapping(value = "/{id}/edit", method = RequestMethod.GET, params = {"type=Zoom"})
//    public ModelAndView editZoom(@PathVariable("id") Long id) {
//
//        ModelAndView modelAndView = new ModelAndView("settings/conference/zoom/zoom-edit");
//
//        ConferenceRoom zoom = conferenceRoomService.load(ConferenceRoom.class, id);
//
//        modelAndView.addObject("zoom", zoom);
//
//        return modelAndView;
//        
//    }
//
//    /**
//     * edit a zoom 
//     * 
//     * @param zoom
//     * @return
//     */
//    @RequestMapping(value = "/{id}", method = RequestMethod.PATCH, params = {"type=Zoom"}, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public @ResponseBody HttpResult onEditZoom(@Preloading("zoomId") ConferenceRoom zoom) {
//
//        HttpResult httpResult = new HttpResult();
//        
//        try {
//            
//            conferenceRoomService.update(zoom);
//
//            httpResult.success().message("修改zoom成功");
//
//        } catch (Exception e) {
//
//            httpResult.fail("500").message("修改zoom失败");
//
//            logger.error("#onEdit() - edit fail, exception is [{}]", e);
//        }
//        return httpResult;
//    }
//
//    /**
//     * prepare to edit webX
//     * 
//     * @param id
//     * @return
//     */
//    @RequestMapping(value = "/{id}/edit", method = RequestMethod.GET, params = {"type=WebEx"})
//    public ModelAndView editWebX(@PathVariable("id") Long id) {
//
//        ModelAndView modelAndView = new ModelAndView("settings/conference/webx/webx-edit");
//
//        ConferenceRoom webX = conferenceRoomService.load(ConferenceRoom.class, id);
//
//        modelAndView.addObject("webX", webX);
//
//        return modelAndView;
//    }
//
//    /**
//     * edit a webX
//     * 
//     * @param webX
//     * @return
//     */
//    @RequestMapping(value = "/{id}", method = RequestMethod.PATCH, params = {"type=WebEx"}, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public @ResponseBody HttpResult onEditWebX(@Preloading("webXId") ConferenceRoom webX) {
//
//        HttpResult httpResult = new HttpResult();
//        
//        try {
//        	
//        	conferenceRoomService.update(webX);
//
//            httpResult.success().message("修改webX成功");
//
//        } catch (Exception e) {
//
//            httpResult.fail("500").message("修改webX失败");
//
//            logger.error("#onEdit() - edit fail, exception is [{}]", e);
//        }
//        return httpResult;
//    }
//
//    /**
//     * prepare to edit zoom room
//     * 
//     * @param id
//     * @return
//     */
//    @RequestMapping(value = "/{id}/edit", method = RequestMethod.GET, params = {"type=BizConf"})
//    public ModelAndView editConfrenceRoom(@PathVariable("id") Long id) {
//
//        ModelAndView modelAndView = new ModelAndView("settings/conference/conference-room/conference-room-edit");
//
//        ConferenceRoom confrenceRoom = conferenceRoomService.load(ConferenceRoom.class, id);
//
//        modelAndView.addObject("conferenceRoom", confrenceRoom);
//
//        return modelAndView;
//    }
//
//    /**
//     *  edit a conference room 
//     * 
//     * @param confrenceRoom
//     * @return
//     */
//    @RequestMapping(value = "/{id}", method = RequestMethod.PATCH, params = {"type=BizConf"}, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
//    public @ResponseBody HttpResult onEditConfrenceRoom(@Preloading("conferenceRoomId") ConferenceRoom confrenceRoom) {
//
//        HttpResult httpResult = new HttpResult();
//        
//        try {
//        	
//        	conferenceRoomService.update(confrenceRoom);
//
//            httpResult.success().message("修改会议室成功");
//
//        } catch (Exception e) {
//            httpResult.fail("500").message("修改会议室失败");
//            logger.error("#onEdit() - edit fail, exception is [{}]", e);
//        }
//        
//        return httpResult;
//        
//    }

}